/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * asignarCita.java
 *
 * Created on 21/03/2012, 03:48:24 PM
 */
package co.edu.eam.clinica.vista.gui.consulta;

import co.edu.eam.clinica.vista.controladores.consulta.controladorConsultaClinica;
import co.edu.eam.clinica.vista.gui.common.BotonOncologos;
import co.edu.eam.clinica.vista.gui.common.PanelOncologos;
import co.edu.eam.clinica.vista.gui.common.VentanaPrincipalManager;
import co.edu.eam.persitencia.entidades.Consulta;
import co.edu.eam.persitencia.entidades.Paciente;
import co.edu.eam.persitencia.enumeraciones.TipoDocumentoEnum;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author diana
 */
public class PanelAsignarCita extends PanelOncologos {

    controladorConsultaClinica control;
   

    /** Creates new form asignarCita */
    public PanelAsignarCita() {
        initComponents();
        control= new controladorConsultaClinica();
        llenarCTipoDocumento();
       
    }
   

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbTipoDocuemnto = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        tfDocumento = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        tfNOmbre = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        tfEps = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTCitas = new javax.swing.JTable();
        bIrCita = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Paciente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel1.setText("Tipo Documento:");

        jLabel2.setText("Documento:");

        jLabel7.setText("Nombre");

        tfNOmbre.setEditable(false);

        jLabel8.setText("EPS");

        tfEps.setEditable(false);

        jButton2.setText("buscar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tfEps, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
                    .addComponent(tfNOmbre, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(cbTipoDocuemnto, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbTipoDocuemnto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfNOmbre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfEps, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Citas Paciente"));

        jTCitas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Medico", "Fecha/hora", "Motivo"
            }
        ));
        jScrollPane1.setViewportView(jTCitas);

        bIrCita.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/torresquintero/oncologos/medico/imagenes/imagenes/24x24/guion-formato-mas-icono-7247-32 - copia.png"))); // NOI18N
        bIrCita.setText("Ir");
        bIrCita.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bIrCitaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(bIrCita)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(bIrCita)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jBBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBBuscarActionPerformed
    
    }//GEN-LAST:event_jBBuscarActionPerformed

    private void jBAsignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAsignarActionPerformed


    }//GEN-LAST:event_jBAsignarActionPerformed

    private void tfEpsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfEpsActionPerformed
       // TODO add your handling code here:
    }//GEN-LAST:event_tfEpsActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    if (tfDocumento.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "digite el documento");
            tfDocumento.requestFocus();
        }else{
        
        String documento=tfDocumento.getText();
        try {
             Paciente paciente = control.buscarPaciente(documento);
            
            tfNOmbre.setText(paciente.getNombre());
            tfEps.setText(paciente.getEps().getNombre());
            cbTipoDocuemnto.setSelectedItem(paciente.getTipoDocumento());
            
            //llenar tabla
            
             DefaultTableModel modelo = new DefaultTableModel();
            this.jTCitas.setModel(modelo);
             
              modelo.setColumnCount(0);
              
            modelo.addColumn("id");
            modelo.addColumn("medico");
            modelo.addColumn("fecha/hora");
            modelo.addColumn("motivo");
            
            List lista = control.listarConsulta_paciente(documento);
            modelo.setNumRows(lista.size());
            
            for (int i = 0; i < lista.size(); i++) {
                
                Consulta con = (Consulta) lista.get(i);
                
                modelo.setValueAt(con.getId(), i, 0);
                modelo.setValueAt(con.getMedico().getNombre(), i, 1);
                modelo.setValueAt(con.getFechaHora(), i, 2);
                modelo.setValueAt(con.getMotivo(), i, 3);
                
                this.jTCitas.setModel(modelo);
            
        }
        } catch (Exception e) {
            e.printStackTrace();
        }}
    }//GEN-LAST:event_jButton2ActionPerformed

    private void bIrCitaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bIrCitaActionPerformed
        //POR PARAMETRO DEL PANEL EL ID DE LA CITA
        try {
            DefaultTableModel modelo=(DefaultTableModel) jTCitas.getModel();
            int id= jTCitas.getSelectedRow();
            long idconsulta=(long) jTCitas.getValueAt(id, 0);

            PanelCitaPac panel = new PanelCitaPac(idconsulta);
            VentanaPrincipalManager.agregarVentana(panel);

//            this.jTCitas.setModel(modelo);
        } catch (Exception ex) {
            Logger.getLogger(PanelBuscarCitas.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_bIrCitaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bIrCita;
    private javax.swing.JComboBox cbTipoDocuemnto;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTCitas;
    private javax.swing.JTextField tfDocumento;
    private javax.swing.JTextField tfEps;
    private javax.swing.JTextField tfNOmbre;
    // End of variables declaration//GEN-END:variables

    private void llenarCTipoDocumento() {
        TipoDocumentoEnum[] tipo=TipoDocumentoEnum.values();
        for (int i = 0; i < tipo.length; i++) {
            cbTipoDocuemnto.addItem(tipo[i]);
            
        }
    }
}
